package com.itheima.api.hashmap.demo03;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashDemo03 {

    public static void main(String[] args) {

        Student s1 = new Student("蓝湛", 15);
        Student s2 = new Student("魏婴", 14);
        Student s3 = new Student("蓝涣", 16);
        Student s4 = new Student("蓝湛", 15);

        HashMap<Student, String> hashMap = new HashMap<>();
        hashMap.put(s1, "云深不知处");
        hashMap.put(s2, "莲花坞");
        hashMap.put(s3, "云深不知处-寒室");
        hashMap.put(s4, "云深不知处-净室");

        Set<Map.Entry<Student, String>> entrySet = hashMap.entrySet();
        for (Map.Entry<Student, String> entry : entrySet){
//            String name = entry.getKey().getName();
            System.out.println(entry.getKey().getName() + "," + entry.getKey().getAge() + "," + entry.getValue());
        }
        System.out.println("------------------------");

        hashMap.forEach((Student stu, String value) -> {
            String name = stu.getName();
            int age = stu.getAge();
            System.out.println(name + "=" + age + "=" + value);
        });

        //第四道练习题：key是student,value也是student
    }
}
